package com.cuiweiyou.vigilesmicrecord.base;

import android.content.Intent;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;

import com.cuiweiyou.vigilesmicrecord.util.comm.CStatusBarUtil;

import java.io.Serializable;

import butterknife.ButterKnife;

/**
 * Created by macpro on 2018/5/3.
 */

public class BaseActivity extends AppCompatActivity {
    final String INTENT_ARG_KEY = "intent_arg";

    @Override
    public void setContentView(int layoutResID) {
        super.setContentView(layoutResID);
        ButterKnife.bind(this);

        CStatusBarUtil.setImmersiveStatusBar(this, true);
    }

    public void delayNextActivityAndFinishCurrent(final Class clazz, int delay) {
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                nextActivityKeepCurrent(clazz);
                finish();
            }
        }, delay);
    }

    public void nextActivityAndFinishCurrent(Class clazz) {
        delayNextActivityAndFinishCurrent(clazz, 0);
    }

    public void nextActivityAndFinishCurrent(Class clazz, Serializable arg) {
        nextActivityKeepCurrent(clazz, arg);
        finish();
    }

    public void nextActivityKeepCurrent(Class clazz) {
        nextActivityKeepCurrent(clazz, null);
    }

    public void nextActivityKeepCurrent(Class clazz, Serializable arg) {
        Intent i = new Intent(this, clazz);
        if (null != arg) {
            i.putExtra(INTENT_ARG_KEY, arg);
        }
        startActivity(i);
    }

    public Serializable getSerializableArg() {
        Intent intent = getIntent();
        return intent.getSerializableExtra(INTENT_ARG_KEY);
    }
}
